'use strict';

/**
 * Config for the router
 */
angular.module('app')
    .run(
        ['$rootScope', '$state', '$stateParams',
         function ($rootScope, $state, $stateParams) {
             $rootScope.$state = $state;
             $rootScope.$stateParams = $stateParams;
         }
        ]
    )
    .config(
        ['$stateProvider', '$urlRouterProvider',
         function ($stateProvider, $urlRouterProvider) {

             $urlRouterProvider
                 .otherwise('/app/dashboard-v1');
             $stateProvider
                 .state('app', {
                     abstract: true,
                     url: '/app',
                     templateUrl: '/static/tpl/app.html'
                 })
                 .state('app.dashboard-v1', {
                     url: '/dashboard-v1',
                     templateUrl: '/static/tpl/app_dashboard_v1.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load(['/static/js/controllers/chart.js']);
                                }]
                     }
                 })
                 .state('app.dashboard-v2', {
                     url: '/dashboard-v2',
                     templateUrl: '/static/tpl/app_dashboard_v2.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load(['/static/js/controllers/chart.js']);
                                }]
                     }
                 })
                 .state('app.ui', {
                     url: '/ui',
                     template: '<div ui-view class="fade-in-up"></div>'
                 })
                 .state('app.ui.buttons', {
                     url: '/buttons',
                     templateUrl: '/static/tpl/ui_buttons.html'
                 })
                 .state('app.ui.icons', {
                     url: '/icons',
                     templateUrl: '/static/tpl/ui_icons.html'
                 })
                 .state('app.ui.grid', {
                     url: '/grid',
                     templateUrl: '/static/tpl/ui_grid.html'
                 })
                 .state('app.ui.widgets', {
                     url: '/widgets',
                     templateUrl: '/static/tpl/ui_widgets.html'
                 })
                 .state('app.ui.bootstrap', {
                     url: '/bootstrap',
                     templateUrl: '/static/tpl/ui_bootstrap.html'
                 })
                 .state('app.ui.sortable', {
                     url: '/sortable',
                     templateUrl: '/static/tpl/ui_sortable.html'
                 })
                 .state('app.ui.portlet', {
                     url: '/portlet',
                     templateUrl: '/static/tpl/ui_portlet.html'
                 })
                 .state('app.ui.timeline', {
                     url: '/timeline',
                     templateUrl: '/static/tpl/ui_timeline.html'
                 })
                 .state('app.ui.tree', {
                     url: '/tree',
                     templateUrl: '/static/tpl/ui_tree.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('angularBootstrapNavTree').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/tree.js');
                                        }
                                    );
                                }
                         ]
                     }
                 })
                 .state('app.ui.toaster', {
                     url: '/toaster',
                     templateUrl: '/static/tpl/ui_toaster.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('toaster').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/toaster.js');
                                        }
                                    );
                                }]
                     }
                 })
                 .state('app.ui.jvectormap', {
                     url: '/jvectormap',
                     templateUrl: '/static/tpl/ui_jvectormap.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('/static/js/controllers/vectormap.js');
                                }]
                     }
                 })
                 .state('app.ui.googlemap', {
                     url: '/googlemap',
                     templateUrl: '/static/tpl/ui_googlemap.html',
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load([
                                                           '/static/js/app/map/load-google-maps.js',
                                                           '/static/js/app/map/ui-map.js',
                                                           '/static/js/app/map/map.js']).then(
                                        function () {
                                            return loadGoogleMaps();
                                        }
                                    );
                                }]
                     }
                 })
                 .state('app.chart', {
                     url: '/chart',
                     templateUrl: '/static/tpl/ui_chart.html',
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load('/static/js/controllers/chart.js');
                                }]
                     }
                 })
                 // table
                 .state('app.table', {
                     url: '/table',
                     template: '<div ui-view></div>'
                 })
                 .state('app.table.static', {
                     url: '/static',
                     templateUrl: '/static/tpl/table_static.html'
                 })
                 .state('app.table.datatable', {
                     url: '/datatable',
                     templateUrl: '/static/tpl/table_datatable.html'
                 })
                 .state('app.table.footable', {
                     url: '/footable',
                     templateUrl: '/static/tpl/table_footable.html'
                 })
                 .state('app.table.grid', {
                     url: '/grid',
                     templateUrl: '/static/tpl/table_grid.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('ngGrid').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/grid.js');
                                        }
                                    );
                                }]
                     }
                 })
                 // form
                 .state('app.form', {
                     url: '/form',
                     template: '<div ui-view class="fade-in"></div>',
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load('/static/js/controllers/form.js');
                                }]
                     }
                 })
                 .state('app.form.elements', {
                     url: '/elements',
                     templateUrl: '/static/tpl/form_elements.html'
                 })
                 .state('app.form.validation', {
                     url: '/validation',
                     templateUrl: '/static/tpl/form_validation.html'
                 })
                 .state('app.form.wizard', {
                     url: '/wizard',
                     templateUrl: '/static/tpl/form_wizard.html'
                 })
                 .state('app.form.fileupload', {
                     url: '/fileupload',
                     templateUrl: '/static/tpl/form_fileupload.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('angularFileUpload').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/file-upload.js');
                                        }
                                    );
                                }]
                     }
                 })
                 .state('app.form.imagecrop', {
                     url: '/imagecrop',
                     templateUrl: '/static/tpl/form_imagecrop.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('ngImgCrop').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/imgcrop.js');
                                        }
                                    );
                                }]
                     }
                 })
                 .state('app.form.select', {
                     url: '/select',
                     templateUrl: '/static/tpl/form_select.html',
                     controller: 'SelectCtrl',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('ui.select').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/select.js');
                                        }
                                    );
                                }]
                     }
                 })
                 .state('app.form.slider', {
                     url: '/slider',
                     templateUrl: '/static/tpl/form_slider.html',
                     controller: 'SliderCtrl',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('vr.directives.slider').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/slider.js');
                                        }
                                    );
                                }]
                     }
                 })
                 .state('app.form.editor', {
                     url: '/editor',
                     templateUrl: '/static/tpl/form_editor.html',
                     controller: 'EditorCtrl',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load('textAngular').then(
                                        function () {
                                            return $ocLazyLoad.load(
                                                '/static/js/controllers/editor.js');
                                        }
                                    );
                                }]
                     }
                 })
                 // pages
                 .state('app.page', {
                     url: '/page',
                     template: '<div ui-view class="fade-in-down"></div>'
                 })
                 .state('app.page.setting', {
                     url: '/setting',
                     templateUrl: '/static/tpl/page_setting.html'
                 })
                 .state('app.page.profile', {
                     url: '/profile',
                     templateUrl: '/static/tpl/page_profile.html'
                 })
                 .state('app.page.post', {
                     url: '/post',
                     templateUrl: '/static/tpl/page_post.html'
                 })
                 .state('app.page.search', {
                     url: '/search',
                     templateUrl: '/static/tpl/page_search.html'
                 })
                 .state('app.page.invoice', {
                     url: '/invoice',
                     templateUrl: '/static/tpl/page_invoice.html'
                 })
                 .state('app.page.price', {
                     url: '/price',
                     templateUrl: '/static/tpl/page_price.html'
                 })
                 .state('app.docs', {
                     url: '/docs',
                     templateUrl: '/static/tpl/docs.html'
                 })
                 // others
                 .state('lockme', {
                     url: '/lockme',
                     templateUrl: '/static/tpl/page_lockme.html'
                 })
                 .state('access', {
                     url: '/access',
                     template: '<div ui-view class="fade-in-right-big smooth"></div>'
                 })
                 .state('access.signin', {
                     url: '/signin',
                     templateUrl: '/static/tpl/page_signin.html',
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['/static/js/controllers/signin.js']);
                                }]
                     }
                 })
                 .state('access.signup', {
                     url: '/signup',
                     templateUrl: '/static/tpl/page_signup.html',
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['/static/js/controllers/signup.js']);
                                }]
                     }
                 })
                 .state('access.forgotpwd', {
                     url: '/forgotpwd',
                     templateUrl: '/static/tpl/page_forgotpwd.html'
                 })
                 .state('access.404', {
                     url: '/404',
                     templateUrl: '/static/tpl/page_404.html'
                 })

                 // fullCalendar
                 .state('app.calendar', {
                     url: '/calendar',
                     templateUrl: '/static/tpl/app_calendar.html',
                     // use resolve to load other dependences
                     resolve: {
                         deps: ['$ocLazyLoad', 'uiLoad',
                                function ($ocLazyLoad, uiLoad) {
                                    return uiLoad.load(
                                        ['/static/vendor/jquery/fullcalendar/fullcalendar.css',
                                         '/static/vendor/jquery/fullcalendar/theme.css',
                                         '/static/vendor/jquery/jquery-ui-1.10.3.custom.min.js',
                                         '/static/vendor/libs/moment.min.js',
                                         '/static/vendor/jquery/fullcalendar/fullcalendar.min.js',
                                         '/static/js/app/calendar/calendar.js']
                                    ).then(
                                        function () {
                                            return $ocLazyLoad.load('ui.calendar');
                                        }
                                    )
                                }]
                     }
                 })

                 // mail
                 .state('app.mail', {
                     abstract: true,
                     url: '/mail',
                     templateUrl: '/static/tpl/mail.html',
                     // use resolve to load other dependences
                     resolve: {
                         deps: ['$ocLazyLoad', 'uiLoad',
                                function ($ocLazyLoad, uiLoad) {
                                    return uiLoad.load([
                                                           '/static/editormd/css/editormd.css',
                                                           '/static/js/editormd.min.js',
                                                           '/static/js/app/mail/mail.js',
                                                           '/static/js/app/mail/mail-service.js',
                                                           '/static/vendor/libs/moment.min.js']
                                    ).then(
                                        function () {
                                            return $ocLazyLoad.load('toaster');
                                        }
                                    )
                                }]
                     }
                 })
                 .state('app.mail.list', {
                     url: '/inbox/{fold}',
                     templateUrl: '/static/tpl/mail.list.html'
                 })
                 .state('app.mail.detail', {
                     url: '/{mailId:[0-9]{1,4}}',
                     templateUrl: '/static/tpl/mail.detail.html'
                 })
                 .state('app.mail.compose', {
                     url: '/compose',
                     templateUrl: '/static/tpl/mail.new.html',
                 })

                 .state('layout', {
                     abstract: true,
                     url: '/layout',
                     templateUrl: '/static/tpl/layout.html'
                 })
                 .state('layout.fullwidth', {
                     url: '/fullwidth',
                     views: {
                         '': {
                             templateUrl: '/static/tpl/layout_fullwidth.html'
                         },
                         'footer': {
                             templateUrl: '/static/tpl/layout_footer_fullwidth.html'
                         }
                     },
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['/static/js/controllers/vectormap.js']);
                                }]
                     }
                 })
                 .state('layout.mobile', {
                     url: '/mobile',
                     views: {
                         '': {
                             templateUrl: '/static/tpl/layout_mobile.html'
                         },
                         'footer': {
                             templateUrl: '/static/tpl/layout_footer_mobile.html'
                         }
                     }
                 })
                 .state('layout.app', {
                     url: '/app',
                     views: {
                         '': {
                             templateUrl: '/static/tpl/layout_app.html'
                         },
                         'footer': {
                             templateUrl: '/static/tpl/layout_footer_fullwidth.html'
                         }
                     },
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['/static/js/controllers/tab.js']);
                                }]
                     }
                 })
                 .state('apps', {
                     abstract: true,
                     url: '/apps',
                     templateUrl: '/static/tpl/layout.html'
                 })
                 .state('apps.note', {
                     url: '/note',
                     templateUrl: '/static/tpl/apps_note.html',
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['/static/js/app/note/note.js',
                                                        '/static/vendor/libs/moment.min.js']);
                                }]
                     }
                 })
                 .state('apps.contact', {
                     url: '/contact',
                     templateUrl: '/static/tpl/apps_contact.html',
                     resolve: {
                         deps: ['uiLoad',
                                function (uiLoad) {
                                    return uiLoad.load(['/static/js/app/contact/contact.js']);
                                }]
                     }
                 })
                 .state('app.weather', {
                     url: '/weather',
                     templateUrl: '/static/tpl/apps_weather.html',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load(
                                        {
                                            name: 'angular-skycons',
                                            files: ['/static/js/app/weather/skycons.js',
                                                    '/static/vendor/libs/moment.min.js',
                                                    '/static/js/app/weather/angular-skycons.js',
                                                    '/static/js/app/weather/ctrl.js']
                                        }
                                    );
                                }]
                     }
                 })
                 .state('music', {
                     url: '/music',
                     templateUrl: '/static/tpl/music.html',
                     controller: 'MusicCtrl',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load([
                                                                'com.2fdevs.videogular',
                                                                'com.2fdevs.videogular.plugins.controls',
                                                                'com.2fdevs.videogular.plugins.overlayplay',
                                                                'com.2fdevs.videogular.plugins.poster',
                                                                'com.2fdevs.videogular.plugins.buffering',
                                                                '/static/js/app/music/ctrl.js',
                                                                '/static/js/app/music/theme.css'
                                                            ]);
                                }]
                     }
                 })
                 .state('music.home', {
                     url: '/home',
                     templateUrl: '/static/tpl/music.home.html'
                 })
                 .state('music.genres', {
                     url: '/genres',
                     templateUrl: '/static/tpl/music.genres.html'
                 })
                 .state('music.detail', {
                     url: '/detail',
                     templateUrl: '/static/tpl/music.detail.html'
                 })
                 .state('music.mtv', {
                     url: '/mtv',
                     templateUrl: '/static/tpl/music.mtv.html'
                 })
                 .state('music.mtvdetail', {
                     url: '/mtvdetail',
                     templateUrl: '/static/tpl/music.mtv.detail.html'
                 })
                 .state('music.playlist', {
                     url: '/playlist/{fold}',
                     templateUrl: '/static/tpl/music.playlist.html'
                 })
                 .state('app.note', {
                     url: '/note',
                     templateUrl: '/static/tpl/form_editor.html',
                     controller: 'EditorCtrl',
                     resolve: {
                         deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load([
                                        'toaster',
                                        'ui.select',
                                        '/static/editormd/css/editormd.css',
                                        '/static/js/editormd.min.js',
                                        '/static/js/controllers/editor.js']);
                                }]
                     }
                 })
         }
        ]
    );